package com.enuo.controller;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import org.springframework.beans.factory.annotation.Autowired;

import com.enuo.utils.AjaxMsg;

public class BaseController
{
    @Autowired
    private Validator validator;

    protected boolean isValidNoMsg(Object target, Class<?>... groups)
    {
        return validator.validate(target, groups).isEmpty();
    }

    public <T> Set<ConstraintViolation<T>> isValid(T target, Class<?>... groups)
    {
        return validator.validate(target, groups);
    }
    
    protected String getParameterErrorMsg()
    {
        return AjaxMsg.failed("参数错误");
    }
}
